<?php

//登陆注册模型
class LoginModel extends Model{
	public $table='user';
	
	
	//注册
	public function zhuce(){
		if(IS_POST){
			$user=Q('post.');
			
			//判断验证码是否错误
			if(strtoupper($user['code']) != strtoupper($_SESSION['code'])){
				$this->error = '验证码错误';
				return false;
			}
			//SQ查询
			$userInfo=$this->where("username='{$user['username']}'")->find();
			if($userInfo){
				$this->error = '用户邮箱已注册过';
			}
			
			$data=array(
			   'username' => $user['username'],
			   'nicname' => $user['nicname'],
			   'password' => md5($user['password']),
			   'time' =>time(),
			   'sex' => $user['sex'],
			   'hearimg' =>$user['hearimg'],
			);
			$this->add($data);
		}
		return true;
	}
	
	//登陆
	public function denglu(){
		if(IS_POST){
			$user=Q('post.');
			//SQ查询
			$userInfo=$this->where("username='{$user['uname']}'")->find();
			if(!$userInfo){
				$this->error = '用户名不存在';
			}
			if($userInfo['password'] != $user['pword']){
				$this->error = '密码错误';
			}
			
		}
		return $userInfo;
	}
	
}

   


?>